<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="CentOS," />










<meta name="description" content="CentOS笔记CentOS（Community Enterprise Operating System，中文意思是：社区企业操作系统）是Linux发行版之一，它是来自于Red Hat Enterprise Linux依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码，因此有些要求高度稳定性的服务器以CentOS替代商业版的Red Hat Enterprise Linux使用。两者的不">
<meta name="keywords" content="CentOS">
<meta property="og:type" content="article">
<meta property="og:title" content="CentOS学习笔记">
<meta property="og:url" content="http://yoursite.com/2018/05/25/CentOS学习笔记/index.html">
<meta property="og:site_name" content="Mr. Lee&#39;s blog">
<meta property="og:description" content="CentOS笔记CentOS（Community Enterprise Operating System，中文意思是：社区企业操作系统）是Linux发行版之一，它是来自于Red Hat Enterprise Linux依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码，因此有些要求高度稳定性的服务器以CentOS替代商业版的Red Hat Enterprise Linux使用。两者的不">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-05-25T14:46:46.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="CentOS学习笔记">
<meta name="twitter:description" content="CentOS笔记CentOS（Community Enterprise Operating System，中文意思是：社区企业操作系统）是Linux发行版之一，它是来自于Red Hat Enterprise Linux依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码，因此有些要求高度稳定性的服务器以CentOS替代商业版的Red Hat Enterprise Linux使用。两者的不">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/05/25/CentOS学习笔记/"/>





  <title>CentOS学习笔记 | Mr. Lee's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Mr. Lee's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">知识改变命运,技术成就梦想</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/05/25/CentOS学习笔记/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Mr. Lee">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Mr. Lee's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">CentOS学习笔记</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-05-25T18:41:06+08:00">
                2018-05-25
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  3,964
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  18
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="CentOS笔记"><a href="#CentOS笔记" class="headerlink" title="CentOS笔记"></a>CentOS笔记</h3><p>CentOS（Community Enterprise Operating System，中文意思是：社区企业操作系统）是Linux发行版之一，它是来自于Red Hat Enterprise Linux依照<a href="https://baike.baidu.com/item/%E5%BC%80%E6%94%BE%E6%BA%90%E4%BB%A3%E7%A0%81" target="_blank" rel="noopener">开放源代码</a>规定释出的源代码所编译而成。由于出自同样的<a href="https://baike.baidu.com/item/%E6%BA%90%E4%BB%A3%E7%A0%81" target="_blank" rel="noopener">源代码</a>，因此有些要求高度稳定性的<a href="https://baike.baidu.com/item/%E6%9C%8D%E5%8A%A1%E5%99%A8" target="_blank" rel="noopener">服务器</a>以CentOS替代商业版的<a href="https://baike.baidu.com/item/Red%20Hat" target="_blank" rel="noopener">Red Hat</a> Enterprise Linux使用。两者的不同，在于CentOS并不包含封闭源代码软件。</p>
<hr>
<p>&lt;&lt;计算机文化&gt;&gt;  —学习计算机基础概念</p>
<hr>
<h5 id="Linux发行版本"><a href="#Linux发行版本" class="headerlink" title="Linux发行版本"></a>Linux发行版本</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Redhat Linux </span><br><span class="line">Ubuntu</span><br><span class="line">CentOS</span><br></pre></td></tr></table></figure>
<h5 id="macOS软件连接"><a href="#macOS软件连接" class="headerlink" title="macOS软件连接"></a>macOS软件连接</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mac</span><br><span class="line">http://xclient.info/?t=cf45be83ba9e7cbc54b5a457f912356b56190ed7</span><br></pre></td></tr></table></figure>
<h5 id="阿里云远程登录报错解决办法"><a href="#阿里云远程登录报错解决办法" class="headerlink" title="阿里云远程登录报错解决办法"></a>阿里云远程登录报错解决办法</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @</span><br><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!</span><br><span class="line">Someone could be eavesdropping on you right now (man-in-the-middle attack)!</span><br><span class="line">It is also possible that a host key has just been changed.</span><br><span class="line">The fingerprint for the RSA key sent by the remote host is</span><br><span class="line">SHA256:37dpXib6L1tiX7BJUdo+oYFQLlGCllIjWo9n/czvRH8.</span><br><span class="line">Please contact your system administrator.</span><br><span class="line">Add correct host key in /Users/lizhonglin/.ssh/known_hosts to get rid of this message.</span><br><span class="line">Offending RSA key in /Users/lizhonglin/.ssh/known_hosts:2</span><br><span class="line">RSA host key for 47.104.85.246 has changed and you have requested strict checking.</span><br><span class="line">Host key verification failed.</span><br><span class="line"></span><br><span class="line">[进程已完成]</span><br></pre></td></tr></table></figure>
<blockquote>
<p>解决方法：</p>
<p>vi ~/.ssh/known_hosts 在本地机器删除对应的密钥信息</p>
<p>方法一：<br>rm -rf ~/.ssh/known_hosts</p>
<hr>
<p>优点：干净利索<br>缺点：把其他正确的公钥信息也删除，下次链接要全部重新经过认证</p>
<p>方法二：<br>vi ~/.ssh/known_hosts<br>删除对应ip的相关rsa信息（本例可知删除53行信息即可）</p>
<hr>
<p>优点：其他正确的公钥信息保留<br>缺点：还要vi，还要找到对应信息，稍微优点繁琐</p>
<p>方法三：<br>清除旧的公钥信息<br>ssh-keygen -R 192.168.0.100</p>
<hr>
<p>优点：快、稳、狠<br>缺点：没有缺点</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ssh登陆出现警告：</span><br><span class="line">ssh登录，permission denied(publickey.gssapi-with-mic)</span><br><span class="line">用ssh登录Linux，出现permission denied(publickey.gssapi-with-mic.password)错误。</span><br><span class="line">解决方法：</span><br><span class="line">修改/etc/ssh/sshd_config文件，PasswordAuthentication no修改为yes</span><br></pre></td></tr></table></figure>
<h5 id="命令"><a href="#命令" class="headerlink" title="命令"></a>命令</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">www.kernel.org  linux 内核下载地址 --&gt;参考-- minix(教学)  </span><br><span class="line">who /w 		查询哪些用户登录呢系统/ 显示跟详细</span><br><span class="line">clear		清屏</span><br><span class="line">ps 		查看shell版本</span><br><span class="line"></span><br><span class="line">adduser 用户名     创建用户</span><br><span class="line">passwd  用户名     创建用户密码 (如果直接回车改当前用户密码/跟上用户名是修改用户名的密码)</span><br><span class="line"></span><br><span class="line">whoami /who am i 查看自己是谁</span><br><span class="line"></span><br><span class="line">logout /exit   登出账户</span><br><span class="line"></span><br><span class="line">shutdown /init 0  	关闭服务器</span><br><span class="line">reboot /init 6   	重启服务器</span><br><span class="line"></span><br><span class="line">uname  		查看自己用的什么系统</span><br><span class="line">hostname  	查看主机名</span><br><span class="line">userdel    	删除用户</span><br><span class="line">wall  警告</span><br><span class="line">敲两下tab键 可以查看当前能使用过的命令数</span><br><span class="line"></span><br><span class="line">man /info(更详细更专业)   查看命名的使用手册 (按q退出 按h是帮助)</span><br><span class="line">pass --help   获取命令帮助信息</span><br><span class="line">显示太长可以加上|    例如:pass --help |less </span><br><span class="line">whatis passwd  获取简短帮助</span><br><span class="line">which python    查找命令在哪里</span><br><span class="line">whereis python  查找命令在哪里</span><br><span class="line"></span><br><span class="line">pwd 显示当前的目录路径</span><br><span class="line"></span><br><span class="line">查看历史命令    history   使用!编号就可以调取</span><br><span class="line">echo  回声命令   </span><br><span class="line">echo $HISTSIZE   查看系统输入的命令历史记录</span><br><span class="line">sodu  以管理员权限做某些事情</span><br><span class="line">ssh 用户名@ip </span><br><span class="line">scp  安全拷贝</span><br></pre></td></tr></table></figure>
<h5 id="实用命令"><a href="#实用命令" class="headerlink" title="实用命令"></a>实用命令</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">su 切换用户</span><br><span class="line">etc  配置目录</span><br><span class="line">usr  用户目录</span><br><span class="line">home 用户家目录</span><br></pre></td></tr></table></figure>
<h5 id="操作文件和文件夹"><a href="#操作文件和文件夹" class="headerlink" title="操作文件和文件夹"></a>操作文件和文件夹</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">touch  创建文件 (如果文件存在会修改文件的最后访问时间)</span><br><span class="line">ls -l   查看长格式</span><br><span class="line">ls -a   查看所有文件</span><br><span class="line">ls      列出所有文件</span><br><span class="line">ls -la  长格式查看全部文件</span><br><span class="line">ls -r   反转顺序</span><br><span class="line">ls -R  递归显示目录</span><br><span class="line"></span><br><span class="line">cd abc/foo</span><br><span class="line">cd ../..</span><br><span class="line">cd ~</span><br><span class="line">rm  remove  既可以删文件又可以删除文件</span><br><span class="line">rm -rf / 慎用</span><br></pre></td></tr></table></figure>
<h5 id="常用操作命令"><a href="#常用操作命令" class="headerlink" title="常用操作命令"></a>常用操作命令</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">history   可以查看当天的历史命令(使用!编号就可以把命令在执行一遍)</span><br><span class="line">cp ----copy 复制文件</span><br><span class="line">mv ---move 剪切移动</span><br><span class="line">cat /head/tail 查看文件内容</span><br><span class="line">cat index.html | more/less  分页查看文件内容</span><br><span class="line">head -5 index.html   查看5行内容</span><br><span class="line">tail -2 index.html   查看最后2两行</span><br><span class="line">cat index.html | grep &apos;&lt;div&gt;&apos; 查询文件中指定的内容</span><br><span class="line">grep &apos;&lt;div&gt;&apos; index.html  也可以这样搜索</span><br><span class="line">grep &apos;&lt;div&gt;&apos; index.html -n  查询多少行有这个对应的数据</span><br><span class="line">grep &apos;&lt;div&gt;&apos; / -R -n  &amp; 让命令在后台执行</span><br><span class="line">grep &apos;&lt;div&gt;&apos; / -R -n &gt; result.txt &amp; 命令在后台执行 并且重新执行</span><br><span class="line">grep &apos;&lt;div&gt;&apos; / -R -n &gt; result.txt  2&gt; error.txt &amp;  错误重定向</span><br><span class="line">&amp; 	在后台执行</span><br><span class="line"></span><br><span class="line">&gt;	是输出重定向</span><br><span class="line">2&gt; 	执行命令错误了 在行另外一个文件</span><br><span class="line">&gt;&gt; 	追加输出重定向</span><br><span class="line">输入重定向用&lt;</span><br><span class="line"></span><br><span class="line">jobs 	可以查看后台有没有任务在执行</span><br><span class="line">fg %1	把任务拿前台来执行</span><br><span class="line">bg %1   在次把任务拿到后台执行</span><br><span class="line">top     查看cpu的占用率</span><br><span class="line">grep 搜文件内容中 </span><br><span class="line">wc  数行数和单词数</span><br><span class="line">uniq 去掉相邻的重复的内容</span><br><span class="line">sort 对内容排序(返回修改后的列表,不改变文件的内容)</span><br><span class="line">diff 版本比较两个文件的内容</span><br><span class="line">file 分析文件的性质(根据文件里面数据的特征值来分析)</span><br><span class="line"></span><br><span class="line">find 查找文件 </span><br><span class="line">ctrl+c     终止一个命令的执行</span><br></pre></td></tr></table></figure>
<h5 id="远程拷贝文件"><a href="#远程拷贝文件" class="headerlink" title="远程拷贝文件"></a>远程拷贝文件</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">ssh  用户名@ip </span><br><span class="line"></span><br><span class="line">scp he hellokitty@120.77.222.217:/home/hellokitty/</span><br><span class="line"></span><br><span class="line">CentOS:</span><br><span class="line">cat /etc/centos-release  查看操作系统版本</span><br><span class="line">[root@izm5eifctth7468z9e6fz0z ~]# cat /etc/centos-release</span><br><span class="line">CentOS Linux release 7.4.1708 (Core)</span><br><span class="line">[root@izm5eifctth7468z9e6fz0z ~]#</span><br></pre></td></tr></table></figure>
<h5 id="创建硬链接-软链接"><a href="#创建硬链接-软链接" class="headerlink" title="创建硬链接/软链接"></a>创建硬链接/软链接</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ln filename 目录   创建硬链接</span><br><span class="line"></span><br><span class="line">ln -s  /etc/e.txt  filename    创建软连接相当于windows下面的快捷方式.</span><br><span class="line">ln -s ~/guess.py  /usr/bin/guess   创建软链接</span><br></pre></td></tr></table></figure>
<h5 id="redis下载地址"><a href="#redis下载地址" class="headerlink" title="redis下载地址"></a>redis下载地址</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">redis.io</span><br><span class="line">http://download.redis.io/releases/redis-3.2.11.tar.gz</span><br></pre></td></tr></table></figure>
<h5 id="下载文件的压缩-解压缩-归档-解归档"><a href="#下载文件的压缩-解压缩-归档-解归档" class="headerlink" title="下载文件的压缩/解压缩/归档/解归档"></a>下载文件的压缩/解压缩/归档/解归档</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">解压缩</span><br><span class="line"></span><br><span class="line">后缀为gz的</span><br><span class="line">gzip   文件    压缩</span><br><span class="line">gunzip  文件名      解压文件   -v 可以看见详细的解压过程</span><br><span class="line"></span><br><span class="line">后缀为xz的</span><br><span class="line">xz -z</span><br><span class="line">xz -d</span><br><span class="line">xz -z -9  压缩比</span><br><span class="line"></span><br><span class="line">解归档</span><br><span class="line">[root@izm5eifctth7468z9e6fz0z ~]# tar -xvf redis-3.2.11.tar</span><br><span class="line"></span><br><span class="line">归档</span><br><span class="line">tar -cvf all.tar *  *表示归档当前目录所有文件</span><br><span class="line">tar -xvf all.tar   解归档</span><br></pre></td></tr></table></figure>
<h5 id="别名-和-反别名"><a href="#别名-和-反别名" class="headerlink" title="别名 和 反别名"></a>别名 和 反别名</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">alias ll= 'ls -l'    定制别名</span><br><span class="line"></span><br><span class="line">unalias ll     反别名</span><br></pre></td></tr></table></figure>
<h5 id="vim使用"><a href="#vim使用" class="headerlink" title="vim使用"></a>vim使用</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">syntax off  关闭高亮语法</span><br><span class="line">syntax no 开启</span><br><span class="line">set ts = 4  设置tap键 为4个空格</span><br><span class="line">修改vim配置文件:</span><br><span class="line">[root@izm5eifctth7468z9e6fz0z ~]# vim .vimrc</span><br><span class="line"></span><br><span class="line">!v 可以打开刚才执行过以v开头的在执行一遍</span><br><span class="line">ming</span><br><span class="line"></span><br><span class="line">在末行模式下面要执行系统命令可以</span><br><span class="line">! 命令</span><br><span class="line">要回vim  按回车</span><br><span class="line"></span><br><span class="line">在末行模式:</span><br><span class="line">:inoremap pymain if __name__ == &apos;__main__&apos;:  </span><br><span class="line"></span><br><span class="line">命令模式输入</span><br><span class="line">/  可以做搜索    n 向下搜索   N向上搜索</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">排版</span><br><span class="line">.center() 字符串居中</span><br><span class="line">rjust()  右对齐</span><br><span class="line">ljust()   左对齐</span><br></pre></td></tr></table></figure>
<h5 id="修改文件权限"><a href="#修改文件权限" class="headerlink" title="修改文件权限"></a>修改文件权限</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">chmod u+x,g+x,O+x 文件   修改文件的权限</span><br><span class="line">chomd 777 读写执行</span><br><span class="line">      744 只读</span><br><span class="line">      766 读写</span><br><span class="line">      555 读执行</span><br></pre></td></tr></table></figure>
<h5 id="升级python3"><a href="#升级python3" class="headerlink" title="升级python3"></a>升级python3</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">原文地址:https://blog.csdn.net/jackfrued/article/details/79380979</span><br><span class="line"></span><br><span class="line">1.wget  https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz</span><br><span class="line">2.xz -d Python-3.6.5.tar.xz</span><br><span class="line">3.tar -xvf Python-3.6.5.tar</span><br><span class="line">**4.yum install gcc</span><br><span class="line">5.cd Python-3.6.5</span><br><span class="line">6. ./configure --prefix=/usr/local/python36 --enable-optimizations</span><br><span class="line">7. 编译:make &amp;&amp; make install   (&amp;&amp;表示执行完前面的命令在执行后面的) 这步错了执行以下</span><br><span class="line">yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel</span><br><span class="line"></span><br><span class="line">8. ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3</span><br></pre></td></tr></table></figure>
<h6 id="预习"><a href="#预习" class="headerlink" title="预习"></a>预习</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">NginX   Web服务器</span><br><span class="line">MySQL   关系型数据库  -持久化</span><br><span class="line">Redis   非关系型数据库</span><br><span class="line"></span><br><span class="line">防火墙   iptables/firewall</span><br><span class="line"></span><br><span class="line">[] -第二大的元素找出来</span><br><span class="line">['','',''] -重复次数排前三的找出来</span><br></pre></td></tr></table></figure>
<h6 id="pip"><a href="#pip" class="headerlink" title="pip"></a>pip</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">pip3 install  pycodestyle  python代码规范检查</span><br><span class="line"></span><br><span class="line">升级pip:</span><br><span class="line"> [root@izm5eifctth7468z9e6fz0z ~]# pip3 install --upgrade pip</span><br><span class="line"> </span><br><span class="line"> jupyter notebook</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"> sys.argv  python接收系统传给的参数包括系统本身</span><br></pre></td></tr></table></figure>
<h4 id="linux-安装软件"><a href="#linux-安装软件" class="headerlink" title="linux 安装软件"></a>linux 安装软件</h4><h6 id="包管理工具"><a href="#包管理工具" class="headerlink" title="包管理工具"></a>包管理工具</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum   yellowdog updater modified</span><br><span class="line">rpm   redhat package  manager</span><br></pre></td></tr></table></figure>
<h6 id="yum的使用"><a href="#yum的使用" class="headerlink" title="yum的使用"></a>yum的使用</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum list installed  检查安装了哪些软件</span><br><span class="line"> yum search  nginx   看看是否有安装资源</span><br><span class="line"> yum makecache</span><br></pre></td></tr></table></figure>
<h6 id="常用的web架构"><a href="#常用的web架构" class="headerlink" title="常用的web架构"></a>常用的web架构</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">LAMP   = Linux + Apache + MySQL + PHP</span><br><span class="line"> 		 Linux + Nginx + MySQL + Python</span><br></pre></td></tr></table></figure>
<h6 id="nginx配置"><a href="#nginx配置" class="headerlink" title="nginx配置"></a>nginx配置</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">iptables -L -n   查看端口状态</span><br><span class="line"></span><br><span class="line">nginx:首页位置</span><br><span class="line"> /usr/share/nginx/html.</span><br><span class="line"> </span><br><span class="line">编辑配置文件</span><br><span class="line"> /etc/nginx/nginx.conf.</span><br><span class="line"> </span><br><span class="line">nginx -s stop 停了</span><br><span class="line"></span><br><span class="line">启动</span><br><span class="line">nginx</span><br><span class="line"></span><br><span class="line">Nginx的启动(start),停止(stop)命令</span><br><span class="line">查看Nginx的版本号：nginx -V</span><br><span class="line"></span><br><span class="line">启动Nginx：start nginx</span><br><span class="line"></span><br><span class="line">快速停止或关闭Nginx：nginx -s stop</span><br><span class="line"></span><br><span class="line">正常停止或关闭Nginx：nginx -s quit</span><br></pre></td></tr></table></figure>
<h6 id="sftp操作"><a href="#sftp操作" class="headerlink" title="sftp操作"></a>sftp操作</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">命令:sftp root@ip </span><br><span class="line"></span><br><span class="line">lizhonglindeMacBook-Pro:~ lizhonglin$ sftp root@47.104.205.141 </span><br><span class="line">root@47.104.205.141's password: </span><br><span class="line">Permission denied, please try again.</span><br><span class="line">root@47.104.205.141's password: </span><br><span class="line">Connected to 47.104.205.141.</span><br><span class="line"><span class="meta">sftp&gt;</span><span class="bash"> ls</span></span><br><span class="line">Python-3.6.5        Python-3.6.5.tar    abc                 homework01.py       </span><br><span class="line">homework02.py       homework03.py       homework04.py       homewrok03.py       </span><br><span class="line">in.html             index.html          redis-3.2.11        redis-3.2.11.tar    </span><br><span class="line">two.py              </span><br><span class="line"><span class="meta">sftp&gt;</span><span class="bash"> <span class="built_in">cd</span> /usr/share/html</span></span><br><span class="line">Couldn't stat remote file: No such file or directory</span><br><span class="line"><span class="meta">sftp&gt;</span><span class="bash"> <span class="built_in">cd</span> /usr/share/nginx/html</span></span><br><span class="line"><span class="meta">sftp&gt;</span><span class="bash"> ls</span></span><br><span class="line">404.html        50x.html        index.html      nginx-logo.png  poweredby.png   </span><br><span class="line"><span class="meta">sftp&gt;</span><span class="bash"> get 上传</span></span><br><span class="line">put 上传</span><br><span class="line"></span><br><span class="line">查看进程</span><br><span class="line">ps -ef </span><br><span class="line">ps -aux </span><br><span class="line"></span><br><span class="line">查看网络状态并且能看见进程号</span><br><span class="line">netstat -nap </span><br><span class="line"></span><br><span class="line">杀进程</span><br><span class="line">kill  进程号</span><br><span class="line"></span><br><span class="line">yum配置</span><br><span class="line"> /etc/yum.repos.d/</span><br><span class="line">拷贝其他两个文件</span><br><span class="line"> </span><br><span class="line">修改后用</span><br><span class="line"> yum makecache</span><br></pre></td></tr></table></figure>
<h6 id="rpm"><a href="#rpm" class="headerlink" title="rpm"></a>rpm</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh   安装   </span><br><span class="line">rpm -e     移除</span><br><span class="line"></span><br><span class="line">rpm -qa | grep 包    查询软件是否安装过</span><br><span class="line"></span><br><span class="line">rpm -qa | grep jdk | xargs rpm -e  查询后再删除(xargs:前面的搜索结果当成参数使用)</span><br></pre></td></tr></table></figure>
<h6 id="安装MySQL"><a href="#安装MySQL" class="headerlink" title="安装MySQL"></a>安装MySQL</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">Mariadb:</span><br><span class="line">yum install mariadb-server mariadb    安装服务器和客户端</span><br><span class="line"></span><br><span class="line">systemctl  start mariadb        7以下低版本的是  service  服务名 start</span><br><span class="line">           stop                         停服务        chkconfig </span><br><span class="line">           restart</span><br><span class="line">           </span><br><span class="line">systemctl status mariadb   查看服务是否启动</span><br><span class="line"></span><br><span class="line">[root@izm5eifctth7468z9e6fz0z ~]# mysql -u root -p  连接mysql</span><br><span class="line"></span><br><span class="line">firewall-cmd   --add-port=80/tcp --permanent --zone=public  配置防火墙</span><br><span class="line"></span><br><span class="line">设置开机自启:</span><br><span class="line"></span><br><span class="line">system enable mariadb    开机自启</span><br><span class="line"></span><br><span class="line">system disenble mariadb  取消开机自启</span><br></pre></td></tr></table></figure>
<h6 id="redis安装"><a href="#redis安装" class="headerlink" title="redis安装"></a>redis安装</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">解压文件</span><br><span class="line"></span><br><span class="line">make</span><br><span class="line">make install</span><br><span class="line"></span><br><span class="line">redis.conf 先备份到商机目录 原文件不要动</span><br><span class="line"></span><br><span class="line">61行 改成自己的内网地址  </span><br><span class="line"></span><br><span class="line">80行 port 端口号  可以修改或者不该    6379 merz</span><br><span class="line"></span><br><span class="line">480行   require    480 requirepass 密码</span><br><span class="line"></span><br><span class="line">redis-server myredis.conf  启动服务</span><br><span class="line">ctrl+c  结束</span><br><span class="line">kill 进程号   没存盘\</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">在后台运行</span><br><span class="line"></span><br><span class="line">redis-server myredis.conf &gt; myredis.log &amp;</span><br><span class="line"></span><br><span class="line">jobs  fg %1      %后台编号</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">[root@izm5eifctth7468z9e6fz0z ~]# redis-server myredis.conf</span><br><span class="line">                _._</span><br><span class="line">           _.-``__ ''-._</span><br><span class="line">      _.-``    `.  `_.  ''-._           Redis 3.2.11 (00000000/0) 64 bit</span><br><span class="line">  .-`` .-```.  ```\/    _.,_ ''-._</span><br><span class="line"> (    '      ,       .-`  | `,    )     Running in standalone mode</span><br><span class="line"> |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379</span><br><span class="line"> |    `-._   `._    /     _.-'    |     PID: 11259</span><br><span class="line">  `-._    `-._  `-./  _.-'    _.-'</span><br><span class="line"> |`-._`-._    `-.__.-'    _.-'_.-'|</span><br><span class="line"> |    `-._`-._        _.-'_.-'    |           http://redis.io</span><br><span class="line">  `-._    `-._`-.__.-'_.-'    _.-'</span><br><span class="line"> |`-._`-._    `-.__.-'    _.-'_.-'|</span><br><span class="line"> |    `-._`-._        _.-'_.-'    |</span><br><span class="line">  `-._    `-._`-.__.-'_.-'    _.-'</span><br><span class="line">      `-._    `-.__.-'    _.-'</span><br><span class="line">          `-._        _.-'</span><br><span class="line">              `-.__.-'</span><br><span class="line">              </span><br><span class="line">              </span><br><span class="line">连接服务器:</span><br><span class="line"></span><br><span class="line">[root@izm5eifctth7468z9e6fz0z ~]# redis-cli -h 172.31.219.49 -p 6379</span><br><span class="line"></span><br><span class="line">172.31.219.49:6379&gt; auth 密码</span><br></pre></td></tr></table></figure>
<h6 id="免安装的软件"><a href="#免安装的软件" class="headerlink" title="免安装的软件"></a>免安装的软件</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">1.export  $PATH=         只能一次有效</span><br><span class="line"></span><br><span class="line">2.修改环境变量 .bash_profile</span><br><span class="line">3.修改变量别名   .bashrc</span><br><span class="line"></span><br><span class="line">4.运行:</span><br><span class="line">python3 -m IPython</span><br></pre></td></tr></table></figure>
<h6 id="firewall-使用方法"><a href="#firewall-使用方法" class="headerlink" title="firewall 使用方法"></a>firewall 使用方法</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br></pre></td><td class="code"><pre><span class="line">centos7下Firewall使用详解</span><br><span class="line">安装它，只需</span><br><span class="line"></span><br><span class="line"># yum install firewalld</span><br><span class="line">如果需要图形界面的话，则再安装</span><br><span class="line"># yum install firewall-config</span><br><span class="line"></span><br><span class="line">一、介绍</span><br><span class="line"></span><br><span class="line">防火墙守护 firewalld 服务引入了一个信任级别的概念来管理与之相关联的连接与接口。它支持 ipv4 与 ipv6，并支持网桥，采用 firewall-cmd (command) 或 firewall-config (gui) 来动态的管理 kernel netfilter 的临时或永久的接口规则，并实时生效而无需重启服务。</span><br><span class="line"></span><br><span class="line">Firewall 能将不同的网络连接归类到不同的信任级别，Zone 提供了以下几个级别</span><br><span class="line"></span><br><span class="line">drop: 丢弃所有进入的包，而不给出任何响应</span><br><span class="line">block: 拒绝所有外部发起的连接，允许内部发起的连接</span><br><span class="line">public: 允许指定的进入连接</span><br><span class="line">external: 同上，对伪装的进入连接，一般用于路由转发</span><br><span class="line">dmz: 允许受限制的进入连接</span><br><span class="line">work: 允许受信任的计算机被限制的进入连接，类似 workgroup</span><br><span class="line">home: 同上，类似 homegroup</span><br><span class="line">internal: 同上，范围针对所有互联网用户</span><br><span class="line">trusted: 信任所有连接</span><br><span class="line"></span><br><span class="line">二、使用方法</span><br><span class="line"></span><br><span class="line"># systemctl start firewalld # 启动,</span><br><span class="line"># systemctl enable firewalld # 开机启动</span><br><span class="line"># systemctl stop firewalld # 关闭</span><br><span class="line"># systemctl disable firewalld # 取消开机启动</span><br><span class="line">具体的规则管理，可以使用 firewall-cmd，具体的使用方法可以</span><br><span class="line"></span><br><span class="line">$ firewall-cmd --help</span><br><span class="line">1. 查看规则</span><br><span class="line"></span><br><span class="line">查看运行状态</span><br><span class="line">$ firewall-cmd --state</span><br><span class="line">查看已被激活的 Zone 信息</span><br><span class="line">$ firewall-cmd --get-active-zones</span><br><span class="line">public</span><br><span class="line">interfaces: eth0 eth1</span><br><span class="line">查看指定接口的 Zone 信息</span><br><span class="line">$ firewall-cmd --get-zone-of-interface=eth0</span><br><span class="line">public</span><br><span class="line">查看指定级别的接口</span><br><span class="line">$ firewall-cmd --zone=public --list-interfaces</span><br><span class="line">eth0</span><br><span class="line">查看指定级别的所有信息，譬如 public</span><br><span class="line">$ firewall-cmd --zone=public --list-all</span><br><span class="line">public (default, active)</span><br><span class="line">interfaces: eth0</span><br><span class="line">sources:</span><br><span class="line">services: dhcpv6-client http ssh</span><br><span class="line">ports:</span><br><span class="line">masquerade: no</span><br><span class="line">forward-ports:</span><br><span class="line">icmp-blocks:</span><br><span class="line">rich rules:</span><br><span class="line">查看所有级别被允许的信息</span><br><span class="line">$ firewall-cmd --get-service</span><br><span class="line">查看重启后所有 Zones 级别中被允许的服务，即永久放行的服务</span><br><span class="line">$ firewall-cmd --get-service --permanent</span><br><span class="line"></span><br><span class="line">2. 管理规则</span><br><span class="line"></span><br><span class="line"># firewall-cmd --panic-on # 丢弃</span><br><span class="line"># firewall-cmd --panic-off # 取消丢弃</span><br><span class="line">$ firewall-cmd --query-panic # 查看丢弃状态</span><br><span class="line"># firewall-cmd --reload # 更新规则，不重启服务</span><br><span class="line"># firewall-cmd --complete-reload # 更新规则，重启服务</span><br><span class="line">添加某接口至某信任等级，譬如添加 eth0 至 public，再永久生效</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=public --add-interface=eth0 --permanent</span><br><span class="line">设置 public 为默认的信任级别</span><br><span class="line"></span><br><span class="line"># firewall-cmd --set-default-zone=public</span><br><span class="line">a. 管理端口</span><br><span class="line">列出 dmz 级别的被允许的进入端口</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zome=dmz --list-ports</span><br><span class="line">允许 tcp 端口 8080 至 dmz 级别</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=dmz --add-port=8080/tcp</span><br><span class="line">允许某范围的 udp 端口至 public 级别，并永久生效</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zome=public --add-port=5060-5059/udp --permanent</span><br><span class="line">b. 管理服务</span><br><span class="line">添加 smtp 服务至 work zone</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=work --add-service=smtp</span><br><span class="line">移除 work zone 中的 smtp 服务</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=work --remove-service=smtp</span><br><span class="line">c. 配置 ip 地址伪装</span><br><span class="line">查看</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=external --query-masquerade</span><br><span class="line">打开伪装</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=external --add-masquerade</span><br><span class="line">关闭伪装</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=external --remove-masquerade</span><br><span class="line">d. 端口转发</span><br><span class="line">要打开端口转发，则需要先</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=external --add-masquerade</span><br><span class="line">然后转发 tcp 22 端口至 3753</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3753</span><br><span class="line">转发 22 端口数据至另一个 ip 的相同端口上</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100</span><br><span class="line">转发 22 端口数据至另一 ip 的 2055 端口上</span><br><span class="line"></span><br><span class="line"># firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100</span><br><span class="line">以上都是一些常用方法，更多高级方法，请参考：</span><br><span class="line">https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html</span><br><span class="line">https://fedoraproject.org/wiki/FirewallD</span><br></pre></td></tr></table></figure>
<h6 id="jupyter-配置文件链接"><a href="#jupyter-配置文件链接" class="headerlink" title="jupyter 配置文件链接"></a>jupyter 配置文件链接</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/Users/lizhonglin/.jupyter/jupyter_notebook_config.py</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/WechatIMG26.jpeg" alt="Mr. Lee 微信支付"/>
        <p>微信支付</p>
      </div>
    

    

    

  </div>
</div>

      </div>
    

    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">
            -------------本文结束
            <i class="fa fa-paw"></i>
            感谢您的阅读-------------
        </div>
    
</div>
      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/CentOS/" rel="tag"><i class="fa fa-tag"></i> CentOS</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/05/17/Python中的SQL注射攻击/" rel="next" title="Python中的SQL注射攻击">
                <i class="fa fa-chevron-left"></i> Python中的SQL注射攻击
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/05/25/Web框架Django-一/" rel="prev" title="Web框架Django(一)">
                Web框架Django(一) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/avatar.png"
                alt="Mr. Lee" />
            
              <p class="site-author-name" itemprop="name">Mr. Lee</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">30</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/Leezhonglin" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:380604322@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>

              <ul class="links-of-blogroll-list">

                
                    <span class="links-of-author-item" style="text-align:center">
                      <a href="https://my.csdn.net/jackfrued/" title="大 神" target="_blank">
                        大 神
                      </a>
                    </span>
                
                    <span class="links-of-author-item" style="text-align:center">
                      <a href="https://blog.csdn.net/qq_33196814" title="CSDN" target="_blank">
                        CSDN
                      </a>
                    </span>
                
                    <span class="links-of-author-item" style="text-align:center">
                      <a href="http://www.python.org" title="python" target="_blank">
                        python
                      </a>
                    </span>
                
                    <span class="links-of-author-item" style="text-align:center">
                      <a href="http://redisdoc.com/" title="redis" target="_blank">
                        redis
                      </a>
                    </span>
                

              </ul>


            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#CentOS笔记"><span class="nav-number">1.</span> <span class="nav-text">CentOS笔记</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Linux发行版本"><span class="nav-number">1.0.1.</span> <span class="nav-text">Linux发行版本</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#macOS软件连接"><span class="nav-number">1.0.2.</span> <span class="nav-text">macOS软件连接</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#阿里云远程登录报错解决办法"><span class="nav-number">1.0.3.</span> <span class="nav-text">阿里云远程登录报错解决办法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#命令"><span class="nav-number">1.0.4.</span> <span class="nav-text">命令</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#实用命令"><span class="nav-number">1.0.5.</span> <span class="nav-text">实用命令</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#操作文件和文件夹"><span class="nav-number">1.0.6.</span> <span class="nav-text">操作文件和文件夹</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#常用操作命令"><span class="nav-number">1.0.7.</span> <span class="nav-text">常用操作命令</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#远程拷贝文件"><span class="nav-number">1.0.8.</span> <span class="nav-text">远程拷贝文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#创建硬链接-软链接"><span class="nav-number">1.0.9.</span> <span class="nav-text">创建硬链接/软链接</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#redis下载地址"><span class="nav-number">1.0.10.</span> <span class="nav-text">redis下载地址</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#下载文件的压缩-解压缩-归档-解归档"><span class="nav-number">1.0.11.</span> <span class="nav-text">下载文件的压缩/解压缩/归档/解归档</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#别名-和-反别名"><span class="nav-number">1.0.12.</span> <span class="nav-text">别名 和 反别名</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#vim使用"><span class="nav-number">1.0.13.</span> <span class="nav-text">vim使用</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#修改文件权限"><span class="nav-number">1.0.14.</span> <span class="nav-text">修改文件权限</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#升级python3"><span class="nav-number">1.0.15.</span> <span class="nav-text">升级python3</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#预习"><span class="nav-number">1.0.15.1.</span> <span class="nav-text">预习</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#pip"><span class="nav-number">1.0.15.2.</span> <span class="nav-text">pip</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#linux-安装软件"><span class="nav-number">1.1.</span> <span class="nav-text">linux 安装软件</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#包管理工具"><span class="nav-number">1.1.0.1.</span> <span class="nav-text">包管理工具</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#yum的使用"><span class="nav-number">1.1.0.2.</span> <span class="nav-text">yum的使用</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#常用的web架构"><span class="nav-number">1.1.0.3.</span> <span class="nav-text">常用的web架构</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#nginx配置"><span class="nav-number">1.1.0.4.</span> <span class="nav-text">nginx配置</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#sftp操作"><span class="nav-number">1.1.0.5.</span> <span class="nav-text">sftp操作</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#rpm"><span class="nav-number">1.1.0.6.</span> <span class="nav-text">rpm</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#安装MySQL"><span class="nav-number">1.1.0.7.</span> <span class="nav-text">安装MySQL</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#redis安装"><span class="nav-number">1.1.0.8.</span> <span class="nav-text">redis安装</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#免安装的软件"><span class="nav-number">1.1.0.9.</span> <span class="nav-text">免安装的软件</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#firewall-使用方法"><span class="nav-number">1.1.0.10.</span> <span class="nav-text">firewall 使用方法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#jupyter-配置文件链接"><span class="nav-number">1.1.0.11.</span> <span class="nav-text">jupyter 配置文件链接</span></a></li></ol></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Mr. Lee</span>

  
</div>


  <span class="post-meta-divider">|</span>



  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://github.com/Leezhonglin">Leezhonglin</a> 提供技术支持</div>



  <span class="post-meta-divider">|</span>


<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_uv"></span>
</span>


  <span class="post-meta-divider">|</span>


<span id="busuanzi_container_site_pv">
    本站总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>


  <span class="post-meta-divider">|</span>


</div>


<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共:64.5k字</span>
</div>


  <span class="post-meta-divider">|</span>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
